#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
#include <QLineEdit>
#include <QSqlError>
#include <QMessageBox>
//#include<login.h>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowTitle("OpenChatRoom");
    this->setFixedSize(850,500);
    ui->pushButton->setStyleSheet("background: rgba(255, 255, 255, 90);");
    ui->pushButton_2->setStyleSheet("background: rgba(255, 255, 255, 90);");
    QPixmap pix=QPixmap(":/source/login2.jpg").scaled(this->size());//设置大小
    QPalette palette;
    palette.setBrush(QPalette::Window,QBrush(pix));//QPalette::Background
    this->setPalette(palette);


    //跳转到登录界面
    //LogIn *new_window=new LogIn();
    connect(ui->pushButton,&QPushButton::clicked,this,[=](){
        LogIn *new_window=new LogIn();
        this->hide();
        if(new_window->isauto)
        {
            imfor.setIcon(QMessageBox::Information);
            imfor.setWindowTitle("提示");
            imfor.setText("正在登陆中");
            imfor.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
            imfor.setDefaultButton(QMessageBox::Ok);
            int ret = imfor.exec();
            if(ret == QMessageBox::Ok)
            {
                new_window->on_login_clicked();
            }
            else
            {
                new_window->show();
            }
        }
        else
        {
            new_window->show();
        }


    });

    //打印欢迎字幕
    QLabel *l=new QLabel(this);
    l->setText("Welcome to OpenChatroom");
    //跳转到注册界面
    this->signin=new SignIn();
    connect(ui->pushButton_2,&QPushButton::clicked,this,[=](){
        this->hide();
        this->signin->show();//想要登录后释放之前的界面？
    });
    connect(this->signin,&SignIn::back,this,[=](){
        this->signin->hide();
        this->show();
    });

//    db = QSqlDatabase::addDatabase("QMYSQL");//添加一个mysql数据库
//    db.setHostName("47.115.215.143");//数据库的ip地址 192.168.6.208
//    db.setPort(3307);//端口号,mysql默认是3306,可以上网搜索查询
//    db.setDatabaseName("YUNMYSQL");//数据库的名字
//    db.setUserName("root");//数据库连接的用户名   mysql下创建的用户
//    db.setPassword("123456");
//    qDebug()<<db.open();//qDebug()产生调试信息,信息为数据库是否打开成功
//    if (!db.open()) {
//        qDebug() << "Failed to open database:" << db.lastError();
//    }

}

Widget::~Widget()
{
    delete ui;
}

